import { getCosAuthorization } from "../proxy/bilinAdminVendorProxy";

export interface CosBucketSet {
  prefix: string;
  bucket: string;
  region: string;
  customDomain: string;
}



interface CosAuthorizationCredentials {
  tmpSecretId: string;
  tmpSecretKey: string;
  sessionToken: string;
  expiredTime: number; // 时间戳，单位秒
}

export interface CosAuthorization {
  credentials: CosAuthorizationCredentials;
  bucket: string;
  region: string;
}

export const getAuthorization = async (
  bucketPrefix: string
): Promise<CosAuthorization> => {
  const res = await getCosAuthorization(bucketPrefix);
  const credentials = res.getCredentials()!;

  return {
    credentials: {
      tmpSecretId: credentials.getTmpSecretId(),
      tmpSecretKey: credentials.getTmpSecretKey(),
      sessionToken: credentials.getSessionToken(),
      expiredTime: credentials.getExpiredTime(),
    },
    bucket: res.getBucket(),
    region: res.getRegion(),
  };
};
